<template>
  <div class="container">
    <div v-if="status===200" class="box box-ver box-ac">
      <img class="icon-success" :src="require('../assets/images/icon-success.svg')" alt="">
      <div class="text">授权成功，您可在单多啦智能橱柜查看您的单据</div>
      <div @click="closeWin()" class="button">确定</div>
    </div>
    <div v-if="status && status!==200" class="box box-ver box-ac">
      <img class="icon-success" :src="require('../assets/images/icon-fail.svg')" alt="">
      <div class="text">{{msg}}</div>
      <div @click="closeWin()" class="button button2">确定</div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getQueryString } from '@/assets/js/common'

export default {
  name: 'authorize',
  data () {
    return {
      status: null,
      msg: ''
    }
  },
  computed: {
    ...mapState(['userNum'])
  },
  mounted () {
    let devMac = this.$route.query.devMac || getQueryString('devMac')
    let json = {
      makerAccount: this.userNum,
      devMac
    }
    // alert(JSON.stringify(json))
    this.redirectDDL(json)
  },
  methods: {
    redirectDDL (json) {
      this.$http({
        url: `${this.$config.api.ddlHost}/other/vkwx/pickupBillsByMakerAccount`,
        method: 'post',
        data: {
          makerAccount: json.makerAccount,
          devMac: json.devMac
        }
      }).then(res => {
        console.log('res', res)
        this.status = res.code
        this.msg = res.msg || 'fail'
        // if (res.code === 200) {
        //   this.status = 200
        // } else {
        //   this.$tools.openToast({
        //     msg: res.msg,
        //     duration: 3000
        //   })
        // }
      })
    },
    closeWin () {
      wx.closeWindow()
    }
  }
}
</script>

<style lang="scss" scoped>
.container{
  width:100%;
  height:100%;
  font-size:1rem;
}
.icon-success{
  margin-top:1.5rem;
  width:2rem;
  height:2rem;
}
.text{
  margin-top:1rem;
  font-size:.36rem;
  color:#666;
  text-align:center;
  width:60%;
}
.button{
  width:4.5rem;
  height:.8rem;
  border-radius:.2rem;
  background-color:#09bb07;
  color:#FFF;
  font-size:.4rem;
  line-height: .8rem;
  margin-top:1rem;
  text-align: center;
}
.button2{
  background-color:#d81e06
}
</style>
